package com.dingreading.cloud.admin.controller;

import com.dingreading.cloud.admin.service.CourseTrainTypesService;
import com.dingreading.cloud.common.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/system/courseTrainTypes")
@Api(tags = "总部-学院线下培训分类管理")
public class CourseTrainTypesController {
    @Resource
    private CourseTrainTypesService courseTrainTypesService;

    @ApiOperation(value = "获取主分类列表")
    @PostMapping(value = "/getMainTypes", produces = "application/json; charset=UTF-8")
    public R<Object> getMainTypes(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName
    ) {
        return courseTrainTypesService.getMainTypes(headStaffUid, headStaffName);
    }

    @ApiOperation(value = "分类tree")
    @PostMapping(value = "/treeList")
    public R<Object> treeList(
            HttpServletRequest request,
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "父分类uid") @RequestParam(value = "uid", required = false) String uid
    ) {
        return courseTrainTypesService.treeList(request, headStaffUid, headStaffName, uid);
    }

    @ApiOperation(value = "新增/修改主分类")
    @PostMapping(value = "/newMainType")
    public R<Object> newMainType(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "主分类uid") @RequestParam(value = "uid", required = false) String uid,
            @ApiParam(value = "分类名称") @RequestParam(value = "typeName") String typeName,
            @ApiParam(value = "前端展示序号") @RequestParam(value = "showOrder", required = false) Integer showOrder,
            @ApiParam(value = "是否最后一级 0，否 1，是") @RequestParam(value = "levelEnd") Integer levelEnd
    ) {
        return courseTrainTypesService.newMainType(headStaffUid, headStaffName, uid, typeName, showOrder, levelEnd);
    }

    @ApiOperation(value = "新增/修改子分类")
    @PostMapping(value = "/newChildType")
    public R<Object> newChildCourseType(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "父分类uid") @RequestParam(value = "parentUid") String parentUid,
            @ApiParam(value = "子分类uid") @RequestParam(value = "uid", required = false) String uid,
            @ApiParam(value = "子分类名称") @RequestParam(value = "typeName") String typeName,
            @ApiParam(value = "是否最后一级 0，否 1，是") @RequestParam(value = "levelEnd", required = false) Integer levelEnd
    ) {
        return courseTrainTypesService.newChildType(headStaffUid, headStaffName, parentUid, uid, typeName, levelEnd);
    }

    @ApiOperation(value = "根据UID获取分类信息")
    @PostMapping(value = "/getByUid", produces = "application/json; charset=UTF-8")
    public R<Object> getByUid(
            HttpServletRequest request,
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "分类uid") @RequestParam(value = "uid") String uid
    ) {
        return courseTrainTypesService.getByUid(request, headStaffUid, headStaffName, uid);
    }

    @ApiOperation(value = "更新分类启用状态")
    @PostMapping(value = "/updateEnabled", produces = "application/json; charset=UTF-8")
    public R<Object> updateEnabled(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "分类uid") @RequestParam(value = "uid") String uid,
            @ApiParam(value = "状态 0.禁用 1.启用") @RequestParam(value = "enabled") Integer enabled
    ) {
        return courseTrainTypesService.updateEnabled(headStaffUid, headStaffName, uid, enabled);
    }

    @ApiOperation(value = "删除分类")
    @PostMapping(value = "/dropData", produces = "application/json; charset=UTF-8")
    public R<Object> dropData(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "分类uid") @RequestParam(value = "uid") String uid
    ) {
        return courseTrainTypesService.dropData(headStaffUid, headStaffName, uid);
    }

    @ApiOperation(value = "上移/下移")
    @PostMapping(value = "/upOrDown", produces = "application/json; charset=UTF-8")
    public R<Object> upOrDown(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "分类uid") @RequestParam(value = "uid") String uid,
            @ApiParam(value = "类型 1.上移 2.下移") @RequestParam(value = "type") Integer type
    ) {
        return courseTrainTypesService.upOrDown(headStaffUid, headStaffName, uid, type);
    }

    @ApiOperation(value = "考核要求")
    @PostMapping(value = "/uploadExam", produces = "application/json; charset=UTF-8")
    public R<Object> uploadExam(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "分类uid") @RequestParam(value = "uid") String uid,
            @ApiParam(value = "考核要求") @RequestParam(value = "examRequire") String examRequire,
            @ApiParam(value = "考核文件地址url") @RequestParam(value = "examUrl", required = false) String examUrl
    ) {
        return courseTrainTypesService.uploadExam(headStaffUid, headStaffName, uid, examRequire, examUrl);
    }
}
